from flask import Flask, jsonify
import os

app = Flask(__name__)


@app.route('/ai/<task>/<barcode>', methods=['GET'])
def req(task=None, barcode=None):
    print(task, barcode)
    response_data = {}
    if task == 'mitosis':
        # 核分裂检测任务
        return jsonify({
            "code": 200,
            "success": True,
            "data": str(response_data)
        })
    elif task == 'microinvasion':
        # 微浸润
        return jsonify({
            "code": 200,
            "success": True,
            "data": str(response_data)
        })
    elif task == 'nucseg':
        # 细胞核分割
        return jsonify({
            "code": 200,
            "success": True,
            "data": str(response_data)
        })
    elif task == 'tils':
        # TILs
        return jsonify({
            "code": 200,
            "success": True,
            "data": str(response_data)
        })
    else:
        return jsonify({
            "code": 400,
            "success": False,
            "data": "task not found"
        })


if __name__ == '__main__':
    mask_save_path = "./app_tmp"
    os.makedirs(mask_save_path, exist_ok=True)
    app.run(host='0.0.0.0', port=1024, threaded=True)
